const { app, BrowserWindow, dialog, ipcMain } = require('electron');
const path = require('path');  // 在此处添加对 path 模块的引入
const { MediaRecorder } = require('stream');

function createWindow() {
  const win = new BrowserWindow({
    width: 800,
    height: 600,
    webPreferences: {
      preload: path.join(__dirname, 'preload.js')
    }
  });

  win.loadFile('index.html');
}

let mediaRecorder; 

app.whenReady().then(() => {
  createWindow();

  ipcMain.on('startRecording', async () => {
    try {
      // const recording = await navigator.mediaDevices.getUserMedia({
      //   video: true,
      //   audio: true,
      // });

      // mediaRecorder = new MediaRecorder(recording, { mimeType: 'video/webm' });

      // mediaRecorder.start();
      console.log("开始录屏")
    } catch (err) {
      console.error(err);
    }
  });

  ipcMain.on('stopRecording', () => {
    mediaRecorder.stop();
  });
});

app.on('window-all-closed', () => {
  if (process.platform!== 'darwin') {
    app.quit();
  }
});

app.on('activate', () => {
  if (BrowserWindow.getAllWindows().length === 0) {
    createWindow();
  }
});